package de.schoar.nagroid.service;

import java.util.Calendar;
import java.util.Date;

import de.schoar.nagroid.DM;

public class SleepService {

	private Calendar c = Calendar.getInstance();
	private int m;
	private int h;
	private int time;
	private Date d;
	
	public SleepService(){
		d = c.getTime();
		h = d.getHours();
		m = d.getMinutes();
		time = 100*h + m;
	}
	
	/* return hours of Start Time */
	public int getHourStart(){
		String s = DM.I.getConfiguration().getSleepStart().substring(0, 2);
		return Integer.parseInt(s);
	}
	
	/* return minutes of Start Time */
	public int getMinuteStart(){
		String s = DM.I.getConfiguration().getSleepStart().substring(2, 4);
		return Integer.parseInt(s);
	}

	/* return hours of End Time */
	public int getHourEnd(){
		String s = DM.I.getConfiguration().getSleepEnd().substring(0, 2);
		return Integer.parseInt(s);
	}
	
	/* return minutes of End Time */
	public int getMinuteEnd(){
		String s = DM.I.getConfiguration().getSleepEnd().substring(2, 4);
		return Integer.parseInt(s);
	}

	/* return a integer which contains hours and minutes of StartTime */
	public int getStart(){
		return Integer.parseInt(DM.I.getConfiguration().getSleepStart());
	}
	
	/* return a integer which contains hours and minutes of EndTime */
	public int getEnd(){
		return Integer.parseInt(DM.I.getConfiguration().getSleepEnd());
	}
	
		
	/* return true if service is slepping */
	public boolean isSleeping(){
		if(!DM.I.getConfiguration().getSleepMode())return false;
		else {
			if(getStart() > getEnd()){
				if((time < getStart()) && (time >= getEnd())) return false;
				else return true;
			}
			else {
				if(getStart() < getEnd()){
					if((time >= getStart()) && (time < getEnd())) return true;
					else return false;
				}
				else return true;
			}
		}
	}
}
